<?php

namespace common\models\firstpage;

use common\models\common\Provinces;
use common\models\user\Member;
use Yii;
use yii\behaviors\BlameableBehavior;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\helpers\HashidsHelper;
use common\enums\StatusEnum;
use common\models\base\User;
use common\helpers\RegularHelper;
use common\traits\Tree;


/**
 * This is the model class for table "{{%by_address}}
 *
 *
 * @package common\models\address
 *
 */
class Address extends ActiveRecord
{
    public $titles;
    public $title1;
    public $title2;
    public $uname;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%by_address}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [

            [['id','member_id','name','phone','address'], 'safe'],
            [['status', 'created_at', 'updated_at','province_id','city_id','area_id','title'], 'integer']

        ];
    }



    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'member_id' => '用户',
            'name' => '收件人',
            'phone' => '手机号',
            'status' => '状态',
            'adder.title' => '省',
            'adders.title' => '市',
            'adderq.title' => '区',
            'address' => '详细地址',
            'title' => '默认地址',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
            'province_id' => '省',
            'city_id' => '市',
            'area_id' => '区',
            'uname' => '用户名',
        ];
    }



    public function behaviors()
    {

        return [
            [
                'class' => TimestampBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ]
        ];
    }
    public function getAdder()
    {
        return $this->hasOne(Provinces::class,['id'=>'province_id']);
    }
    public function getAdders()
    {
        return $this->hasOne(Provinces::class,['id'=>'city_id']);
    }
    public function getAdderq()
    {
        return $this->hasOne(Provinces::class,['id'=>'area_id']);
    }
    public function getUser()
    {
        return $this->hasOne(Member::class,['id'=>'member_id']);
    }
}
